def a(x):
    c=0
    for i in range(2,x):
        if x%i==0:
            c+=1
    if c==0:
        return 1
    else:
        return 0
x=input()
maxp=0
for i in range(0,len(x)):
    for j in range(len(x),0,-1):
        if j>i:
            if a(int(x[i:j]))==1:
                if int(x[i:j])>maxp:
                    maxp=int(x[i:j])
print(maxp)
